/**
 * 简单的全局事件总线，用于非父子组件之间的通信
 */
export default {
  // 存储事件
  events: {},
  
  // 订阅事件
  on(eventName, callback) {
    if (!this.events[eventName]) {
      this.events[eventName] = []
    }
    this.events[eventName].push(callback)
  },
  
  // 触发事件
  emit(eventName, ...params) {
    if (this.events[eventName]) {
      this.events[eventName].forEach(callback => {
        callback(...params)
      })
    }
  },
  
  // 取消订阅
  off(eventName, callback) {
    if (this.events[eventName]) {
      if (callback) {
        this.events[eventName] = this.events[eventName].filter(cb => cb !== callback)
      } else {
        delete this.events[eventName]
      }
    }
  }
} 